package sz.szsmk.citizencard.ui.activity;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import android.view.View;

import com.chenenyu.router.annotation.Route;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;

import java.util.List;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.DonationActivityBinding;
import sz.szsmk.citizencard.ioc.Compontent.DaggerCommonActivityComponent;
import sz.szsmk.citizencard.model.network.bean.response.QueryDonationRes;
import sz.szsmk.citizencard.mvp.contract.IDonationContact;
import sz.szsmk.citizencard.mvp.presenter.DonationPresenter;
import sz.szsmk.citizencard.ui.adapter.DonationAdapter;
import sz.szsmk.citizencard.ui.base.IBaseActivity;

/**
 * Copyright (c)2019
 * author: zdh
 * created on: 2019/1/5 13:25
 * description:
 */
@Route("DonationActivity")
public class DonationActivity extends IBaseActivity<DonationPresenter, DonationActivityBinding>
        implements IDonationContact.IDonationView {


    private DonationAdapter donationAdapter;

    @Override
    protected int attachLayoutRes() {
        return R.layout.donation_activity;
    }

    @Override
    protected void initInjector() {
        DaggerCommonActivityComponent.builder().appCompontent(DaggerApplication.getAppComponent())
                .build().inject(this);
    }

    @Override
    protected void initViews() {
//        showLoadingDialog();
        dataBinding.titleLayout.settingTitle.setText("我的捐款");
        dataBinding.titleLayout.back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
//        RecyclerView donationRv = dataBinding.donationRv;
        LinearLayoutManager manager = new LinearLayoutManager(this);
//        donationRv.setLayoutManager(manager);
        donationAdapter = new DonationAdapter(this);

        dataBinding.donationRv.setLayoutManager(new LinearLayoutManager(this));
        dataBinding.donationRv.setAdapter(donationAdapter);

        dataBinding.swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                mPresenter.getDonation();
            }
        });

        dataBinding.swipeRefreshLayout.autoRefresh();


    }

    @Override
    protected void updateViews() {

    }

    @Override
    public void getDonationSucc(QueryDonationRes response) {
        List<QueryDonationRes.CommonwealOrdersBean> commonwealOrders = response.getCommonwealOrders();
        donationAdapter.setViewData(commonwealOrders);
        donationAdapter.notifyDataSetChanged();
        //完成加载并标记没有更多数据
        dataBinding.swipeRefreshLayout.finishLoadMoreWithNoMoreData();
    }

    @Override
    public void getDonationFail() {

    }

}
